# !/usr/bin/env python
"""
    api_spec
    ~~~~~~~


    :Author: swq
    :Date: 2021/07/04 14:34 
"""

from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from apispec_webframeworks.flask import FlaskPlugin
from marshmallow import Schema, fields

# Create an APISpec
spec = APISpec(
    title="Picture Server",
    version="1.0.0",
    openapi_version="3.0.2",
    plugins=[FlaskPlugin(), MarshmallowPlugin()],
)


# Define schemas
class InputSchema(Schema):
    number = fields.Int(description="An integer.", required=True)


class OutputSchema(Schema):
    msg = fields.String(description="A message.", required=True)


class InputAddProject(Schema):
    name = fields.String(description="Project name.", required=True)


class OutputAddProject(Schema):
    name = fields.String(description="Project name.", required=True)


# register schemas with spec
spec.components.schema("Input", schema=InputSchema)
spec.components.schema("Output", schema=OutputSchema)
spec.components.schema("project input", schema=InputAddProject)
spec.components.schema("project output", schema=OutputAddProject)

# add swagger tags that are used for endpoint annotation
tags = [
    {'name': 'testing', 'description': 'For testing the API.'},
    {'name': 'calculation', 'description': 'Functions for calculating.'},
    {'name': 'project', 'description': 'Functions for add project.'}
]

for tag in tags:
    print(f"Adding tag: {tag['name']}")
    spec.tag(tag)
